#include <iostream>
#include <string>
#include <math.h>
using std::string;
using std::cout;
using std::endl;

class Figure {
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};

void display(Figure & fig) {
    cout << fig.getName()
        << "的面积是:"
        << fig.getArea() << endl ;
};

class Rectangle
:public Figure
{
public:
    Rectangle(double a,double b)
        :_a(a)
         ,_b(b)
    {}

    string getName() const override{
        return "矩形";
    }

    double getArea() const override{
        return _a * _b;
    }

private:
    double _a;
    double _b;
};

class Circle
:public Figure
{
public:
    Circle(double rad)
        :_rad(rad)
    {};

    string getName() const override{
        return "圆形";
    }

    double getArea() const override{
        return PI * _rad * _rad;
    }
private:
    double _rad;
    static const double PI;
};
const double Circle::PI = 3.14;

class Triangle
:public Figure
{
public:
    Triangle(double a,double b,double c)
        :_a(a)
         ,_b(b)
         ,_c(c)
    {}

    string getName() const override{
        return "三角形";
    }

    double getArea() const override{
        double p = (_a + _b + _c)/2;
        return sqrt(p * (p - _a) * (p - _b) * (p - _c));
    }
private:
    double _a;
    double _b;
    double _c;
};

void test0(){
    Rectangle r(10, 20);
    Circle c(15);
    Triangle t(3, 4, 5);
    display(r);
    display(c);
    display(t);
}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


